<template>
  <div id="test6" style="display:flex; flex-grow:1; height: 100%">
    <el-card style="width: 100%">
      <el-button @click="handleNew" type="primary" plain>新增学校</el-button>
      <el-row style="margin-top: 20px">
        <el-col :span="2" style="margin-top: 10px">
          <span>学校名称:</span>
        </el-col>
        <el-col :span="5">
          <el-input v-model="queryData.name" placeholder="请输入学校名称" style="width: 200px"></el-input>
        </el-col>
        <el-col :span="2">
          <el-button @click="handleQuery" type="primary">查 询</el-button>
        </el-col>
      </el-row>
      <el-table :data="pageInfo.list" style="width: 100%; margin-top:20px">
        <el-table-column prop label="序号"></el-table-column>
        <el-table-column prop="name" label="学校名称"></el-table-column>
        <el-table-column prop label="上级名称"></el-table-column>
        <el-table-column prop label="负责人电话"></el-table-column>
        <el-table-column prop label="教育阶段"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="180"></el-table-column>
        <el-table-column align="center" fixed="right" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="dialogFormVisible = true">修改</el-button>
            <el-button type="text" size="small" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageInfo.pageNum"
          :page-size="pageInfo.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="pageInfo.total"
        ></el-pagination>
      </div>
    </el-card>

    <!--新增学校弹出框-->
    <el-dialog title="新增学校" :visible.sync="dialognewVisible" center width="30%">
      <el-form class="addSchoolForm" label-width="80px" :model="addSchoolForm">
        <el-form-item label="学校名称">
          <el-input v-model="addSchoolForm.name"></el-input>
        </el-form-item>
        <el-form-item label="学校地址">
          <el-input v-model="addSchoolForm.address"></el-input>
        </el-form-item>
        <el-form-item label="学校类型">
          <el-input v-model="addSchoolForm.type"></el-input>
        </el-form-item>
        <el-form-item label="地区ID">
          <el-input v-model="addSchoolForm.areaId"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleAdd">新 增</el-button>
        <el-button @click="handleAddRest">重 置</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import{querySchool, addSchool, deleteSchool } from "@/api/xiaowu"
export default {
  name: "test6",
  //组件创建
  created() {},
  mounted() {
    this.getList();
  },
  data() {
    return {
      currentPage1: "1",
      //详细信息弹窗可见性
      dialogVisible: false,
      //新增学校弹窗可见性
      dialognewVisible: false,
      //获取详细信息的行数
      row: "",
      // 遮罩层
      loading: false,
      //查询参数
      queryData: {
        name: "",
        areaId: "",
        address: "",
        pageSize: "5",
        pageNum: "1",
      },
      //新增参数
      addSchoolForm: {
        name: undefined,
        address: undefined,
        type: undefined,
        areaId: undefined,
      },
      //表格数据
      pageInfo: {},
      //删除请求参数
      selectArr: [],
    };
  },
  methods: {
    /** 查询记录列表 */
    getList() {
      this.loading = true;
      querySchool(this.queryData).then((response) => {
        this.pageInfo = response.data.pageInfo;
        this.loading = false;
      });
    },
    /**查询记录 */
    handleQuery() {
      console.log(this.queryData);
      this.getList();
      this.$message.success("查询成功");
    },
    /**新增学校弹窗 */
    handleNew() {
      this.dialognewVisible = true;
    },
    /**新增学校操作 */
    handleAdd() {
      console.log(this.newSchoolForm);
      addSchool(this.newSchoolForm);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm('是否确认删除学校"' + row.name + '"的信息?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          console.log(row.name);
          return deleteSchool(row.name);
        })
        .then(() => {
          this.getList();
          this.$message.success("删除成功");
        })
        .catch(() => {});
    },
    /**返回复选框数据 */
    selectionChange(val){
      this.selectArr = [];
      console.log('val',val);
      val.map((item) => {
        this.selectArr.push(item.name)
      })
      // this.selectArr = val;
      console.log("selectArr",this.selectArr);
    },
    /**重置查询表单 */
    handleQueryRest() {},
    /**重置新增表单 */
    handleAddRest() {},
    /**处理分页 */
    handleSizeChange(val) {
      this.queryData.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryData.pageNum = val;
      this.getList();
    },
  },
};
</script>
<style lang="less" scoped>
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
</style>
